import service from '../utils/request';

export const getUserProblemApi = async (page, pageSize) => {
  try {
    const response = await service.get(`/api/admin/problem?page=${page}&pageSize=${pageSize}`);
    return response;
  } catch (error) {
    console.error('Error:', error);
    throw error;
  }
}

export const updateUserProblemApi = async (problem) => {
  try {
    const response = await service.put(`/api/admin/problem`, problem);
    return response;
  } catch (error) {
    console.error('Error:', error);
    throw error;
  }
}

// 根据图片 id 查询文件 url
export const getPictureUrlApi = async (ids,userId) => {
  try {
    const response = await service.get('/api/admin/picture', {
      params: { ids: ids.join(',') ,userId:userId}
    })
    return response
  } catch (error) {
    console.error('Error:', error)
    throw error
  }
}

// 分页查询用户
export const getUserApi = async (params) => {
  try {
    const response = await service.get('/api/admin/user', {
      params: params
    })
    return response
  } catch (error) {
    console.error('Error:', error)
    throw error
  }
}

// 根据userId  修改jobVipEndTime, freeNum
export const updateUserVipApi = async (user) => {
  try {
    const response = await service.put('/api/admin/vip', user)
    return response
  } catch (error) {
    console.error('Error:', error)
    throw error
  }
}

// 查询关键字
export const getKeyApi = async () => {
  try {
    const response = await service.get('/api/admin/key')
    return response
  } catch (error) {
    console.error('Error:', error)
    throw error
  }
}

// 修改关键字
export const updateKeyApi = async (key) => {
  try {
    const response = await service.put('/api/admin/key', key)
    return response
  } catch (error) {
    console.error('Error:', error)
    throw error
  }
}

// 新增关键字
export const saveKeyApi = async (key) => {
  try {
    const response = await service.post('/api/admin/key', key)
    return response
  } catch (error) {
    console.error('Error:', error)
    throw error
  }
}

// 删除关键字
export const deleteKeyApi = async (id) => {
  try {
    const response = await service.delete(`/api/admin/key/${id}`)
    return response
  } catch (error) {
    console.error('Error:', error)
    throw error
  }
}